package com.bite.mybatis.mapper;

import com.bite.mybatis.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {
    @ResultMap("BaseMap")
    @Select("select * from userinfo ")
    public List<UserInfo> queryUserInfos();

    @Select("select * from userinfo where id = ${ss}")
    public List<UserInfo> queryUserInfo( Integer id);
    @Select("select * from userinfo where username = '${name}'")
    UserInfo queryUserInfoByName(String name);

    @Select("select * from userinfo where id = #{id} and username = #{name}")
    public List<UserInfo> queryUserInfoByIdAndName( Integer id,String name);

    @Select("select * from userinfo where id = #{id1} and username = #{name1}")
    public List<UserInfo> queryUserInfoByIdAndName2(@Param("id1") Integer id,@Param("name1") String name);

    @Insert("insert into userinfo(username,password,age,gender,phone)" +
            "values(#{userName},#{password},#{age},#{gender},#{phone})")
    public Integer insert(UserInfo userInfo);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into userinfo(username,password,age,gender,phone)" +
            "values(#{userInfo.userName},#{userInfo.password},#{userInfo.age},#{userInfo.gender},#{userInfo.phone})")
    public Integer insert2(@Param("userInfo") UserInfo userInfo);

    @Delete("delete from userinfo where id =#{id}")
    Integer delete(Integer id);

    @Update("update userinfo set password = #{password} where id = #{id}")
    Integer update(UserInfo userInfo);

    @Select("select id,username,password,age,gender,phone,delete_flag as deleteFlag,create_time as createTime," +
            "update_time as updateTime from userinfo")
    public List<UserInfo> queryUserInfo2( );



    @Results(id ="BaseMap" ,value = {
            @Result(column = "delete_flag",property = "deleteFlag"),
            @Result(column = "create_time",property ="createTime" ),
            @Result(column ="update_time" ,property = "updateTime"),
    })
    @Select("select * from userinfo")
    public List<UserInfo> queryUserInfo3( );

    @Select("select * from userinfo")
    public List<UserInfo> queryUserInfo4();

    @Select("select * from userinfo where username = #{username} and password = #{password}")
    public List<UserInfo> queryUserInfoByNameAndPassword(String username,String password);

    @Select("select * from userinfo where username = '${username}' and password = '${password}'")
    public List<UserInfo> queryUserInfoByNameAndPassword2(String username,String password);

    @Select("SELECT * from userinfo ORDER BY id ${order}")
    public List<UserInfo> queryUserInfoOrder(String order);
    @Select("SELECT * from userinfo where username like CONCAT('%',#{name},'%')")
    public List<UserInfo> queryUserInfoLike(String name);

}
